package engine.logic.walk.Astar
{
	import flash.geom.Point;

	/**
	 * @author gf
	 */	
	
	public class MathUtil
	{
		
		public static function getLineFunc(ponit1:Point, point2:Point, type:int=0):Function
		{
			var resultFuc:Function;
			

			if( ponit1.x == point2.x )
			{
				if( type == 0 )
				{
					throw new Error("两点所确定直线垂直于y轴，不能根据x值得到y值");
				}
				else if( type == 1 )
				{
					resultFuc =	function( y:Number ):Number
								{
									return ponit1.x;
								}
						
				}
				return resultFuc;
			}
			else if( ponit1.y == point2.y )
			{
				if( type == 0 )
				{
					resultFuc =	function( x:Number ):Number
					{
						return ponit1.y;
					}
				}
				else if( type == 1 )
				{
					throw new Error("两点所确定直线垂直于y轴，不能根据x值得到y值");
				}
				return resultFuc;
			}
			
			var a:Number;
			
			a = (ponit1.y - point2.y) / (ponit1.x - point2.x);
			
			var b:Number;
			
			b = ponit1.y - a * ponit1.x;
			
			if( type == 0 )
			{
				resultFuc =	function( x:Number ):Number
							{
								return a * x + b;
							}
			}
			else if( type == 1 )
			{
				resultFuc =	function( y:Number ):Number
				{
					return (y - b) / a;
				}
			}
			
			return resultFuc;
		}
		
		/**
		 * 得到两点间连线的斜率 
		 * @param ponit1	
		 * @param point2
		 * @return 			两点间连线的斜率 
		 * 
		 */		
		public static function getSlope( ponit1:Point, point2:Point ):Number
		{
			return (point2.y - ponit1.y) / (point2.x - ponit1.x); 
		}
		
		

	}
}